#pragma once
#include "RenderObject.h"
#include "Matrix.h"
#include "protocol.h"
#include "MyMath.h"
using namespace NBE;
namespace NOEXIT
{
	enum PLAYERSTATE
	{
		normal = 0,
		dead = 1
	};

	class Player
	{
	public:
		Player();
		~Player();
		inline RenderObject* getRenderObjcet(){return pRO;}

		void applyImpulse(const vec3f& impulse);
		void rotate(const vec3f& change);
		
		void updatePos();//for drawing

		inline vec3f getPos(){return m_pos;};
		inline Matrix4f& getPosMat()
		{
			return m_pos_mat;
		}
		inline void setPos(vec3f& po){m_pos = po;}
		inline void moveToSyncPos()
		{
			//m_pos = m_sync_pos;
			m_pos = Lerp<vec3f,float>(m_pos,m_sync_pos,0.05f);		 
		}
		inline void setRot(vec3f& ro){m_rotation = ro;}
		inline void setVel(vec3f& ve){m_velocity = ve;}
		inline vec3f getVel(){return m_velocity;}
		inline vec3f getDir(){return m_dir;}

		inline void setPlayerInfo(PlayerInfo* pinfo)
		{
			playerId = pinfo->playerId;
			m_sync_pos = m_pos = vec3f(pinfo->pos);
			m_rotation = vec3f(pinfo->rotation);
			m_rot_mat= Matrix3f::fromEulerAngles( m_rotation.x  , m_rotation.y , m_rotation.z  );
			m_velocity = vec3f(pinfo->velocity);
		}

		inline PlayerInfo getPlayerInfo()
		{
			memcpy(info.pos, &m_pos[0], 3*sizeof(float));
			memcpy(info.rotation, &m_rotation[0], 3*sizeof(float));
			memcpy(info.velocity, &m_velocity[0], 3*sizeof(float));
			info.state = state;
			return info;
		}

		int getPlayerId(){return playerId;}
		void setPlayerId(int i);

		inline Matrix3f& getRotMat3f(){return m_rot_mat;}
	private:
		int playerId;
		int health;
		vec3f m_pos;
		Matrix4f m_pos_mat;
		vec3f m_sync_pos;//server send me the pos
		vec3f m_dir;
		vec3f m_rotation;
		Matrix3f m_rot_mat;
		vec3f m_velocity;

		PLAYERSTATE state;
		PlayerInfo info;

		RenderObject* pRO;
	};
}